/**
 * 
 */
package com.haisen.lee.serviceimpl;

import java.net.URL;
import java.util.Map;

import org.w3c.dom.NamedNodeMap;
import org.w3c.dom.Node;
import org.w3c.dom.NodeList;

import com.haisen.lee.domain.FormDictionary;
import com.haisen.lee.exception.NotImplementException;
import com.haisen.lee.service.IDomParser;
import com.haisen.lee.util.DOMParserType;

/**
 * @author Haisen Lee
 * 
 */
public class SimpleDomParserSupport implements IDomParser {

	private URL url;
	private DOMParserType selfDomParser;
	private NamedNodeMap htmlAttributes = null;

	/**
	 * 
	 */
	public SimpleDomParserSupport() {
		this.init();
	}

	public void contentExtractor(Node root) throws NotImplementException {
		this.htmlAttributes = root.getAttributes();
		NodeList nodeList = root.getChildNodes();
		for (int i = 0; i < nodeList.getLength(); i++) {
			Node childNode = nodeList.item(i);
			String nodeName = childNode.getNodeName().toUpperCase();
			Map<String, DOMParserType> dealDomParserMap = selfDomParser
					.getDealDOMParserType();
			if (dealDomParserMap.containsKey(nodeName)) {
				// generate thread related to node name
				parserChildNode(root, selfDomParser, childNode,
						dealDomParserMap.get(nodeName));
			}
		}

	}

	public void parserChildNode(Node root, DOMParserType rootType,
			Node childNode, DOMParserType childNodeType)
			throws NotImplementException {
		throw new NotImplementException();
	}

	public void init() {

	}

	/**
	 * 
	 * Haisen Lee 2010-5-17
	 * 
	 * @return
	 */
	public DOMParserType getSelfDomParser() {
		return selfDomParser;
	}

	/**
	 * 
	 * Haisen Lee 2010-5-17
	 * 
	 * @param selfDomParser
	 */
	public void setSelfDomParser(DOMParserType selfDomParser) {
		this.selfDomParser = selfDomParser;
	}

	/**
	 * @param htmlAttributes
	 *            the htmlAttributes to set
	 */
	public void setHtmlAttributes(NamedNodeMap htmlAttributes) {
		this.htmlAttributes = htmlAttributes;
	}

	/**
	 * @return the htmlAttributes
	 */
	public NamedNodeMap getHtmlAttributes() {
		return htmlAttributes;
	}

	@Override
	public void setUrl(URL url) {
		this.url = url;

	}

	@Override
	public String toString() {
		return "selfDomParserType : " + selfDomParser + "\t" + "url : " + url;
	}

	@Override
	public void setFormDictionary(FormDictionary formDictionary) {
		
	}

}
